<template>
  <div>
    <!-- <el-form ref="form" :model="paramsintel" label-width="100px" :inline="true">
      <el-form-item label="建议维修时间" prop="maintainTime">
        <el-select filterable clearable style="width: 140px" v-model="paramsintel.maintainTime" placeholder="请选择">
          <el-option v-for="dict in maintainTimeobj" :key="dict.id" :label="dict.maintainTime" :value="dict.maintainTime"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="维修内容" prop="maintainContent">
        <el-input style="width: 140px" v-model="paramsintel.maintainContent" placeholder="请输入" />
      </el-form-item>
      <el-form-item label-width="50px" label="里程" prop="centerMileageNumber">
        <el-input style="width: 140px" v-model="paramsintel.centerMileageNumber" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="维修类型" prop="maintainType">
        <el-select filterable clearable style="width: 140px" v-model="paramsintel.maintainType" placeholder="请选择">
          <el-option v-for="dict in maintainTypeobj" :key="dict.id" :label="dict.maintainType" :value="dict.maintainType"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label=" " prop="" label-width="30px">
        <el-button type="primary" @click="paramsintelQuery" style="width: 80px">查询</el-button>
        <el-button @click="paramsintelReset" style="width: 80px">重置</el-button>
      </el-form-item>
    </el-form> -->
    <el-table :key="Math.random()" :data="maintainList" :height="heightTable" border>
      <el-table-column label="序号" type="index" width="55px"></el-table-column>
      <el-table-column label="日期" prop="workDate"> </el-table-column>
      <!-- <el-table-column label="任务id" prop="id"></el-table-column> -->
      <el-table-column label="维修内容" prop="maintainContent"> </el-table-column>
      <el-table-column label="影响范围" prop="influenceScope"> </el-table-column>
      <el-table-column label="维修类型" prop="maintainType"> </el-table-column>
      <el-table-column label="行别" prop="progressType"> </el-table-column>
      <el-table-column label="未排期的维修数量" prop="maintainNumber"> </el-table-column>
      <el-table-column label="未排期的维修地段" prop="maintainLot">
        <!-- <template #default="scope">
          <span v-if="scope.row.maintainType.slice(0, 3).indexOf('桥隧涵') != -1 && props.TableType.indexOf('维修类型') != -1">
            {{ scope.row.btcName + " " + (scope.row.maintainLot ? scope.row.maintainLot : "/") }}
          </span>
          <span v-else>{{ scope.row.maintainLot }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="备注" prop="remark">
        <template #default="scope">
          <span v-if="scope.row.remark?.length <= 20">
            {{ scope.row.remark }}
          </span>
          <span v-else-if="!scope.row.remark?.length"> --- </span>
          <span v-else>
            <el-popover effect="dark" placement="top-start" :width="400" trigger="hover" :content="scope.row.remark">
              <template #reference> {{ scope.row.remark?.slice(0, 20) }}... </template>
            </el-popover>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="最后更新时间" prop="updateTime"> </el-table-column>
      <el-table-column v-if="props.TableType.indexOf('不添加') == -1" label="操作">
        <template #default="scope">
          <el-button link type="primary" @click="addButtom(scope.row)">添加</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="工区" v-model="isShowWorkArea" width="550px" append-to-body draggable>
      <tree @handleCheckTree="handleCheckTree"></tree>
    </el-dialog>
  </div>
</template>

<script setup name="intelligence">
import tree from "./tree.vue";
const props = defineProps({
  QueryType: {
    type: Array,
    default: [],
  },
  TableType: {
    type: Array,
    default: [],
  },
  DragType: {
    type: String,
    default: "",
  },
  formaMaintainContentList: {
    type: Function,
    default: () => {},
  },
  heightTable: {
    type: String,
    default: "50vh",
  },
  workAreaTree: {
    type: Object,
    default: {},
  },
});
defineExpose({ maintainchildrenFun, getList1 });
const emit = defineEmits(["intelligenceFun2"]);
import { selectWeeklyMaintainContentListapi } from "@/api/main/api.js";
import { nextTick } from "vue";
const isShowWorkArea = ref(false);
const data = reactive({
  paramsintel: {
    workArea: "",
    workAreaId: "",
    maintainTime: "",
    maintainContentId: "",
    btcName: "",
    maintainType: "",
  },
  maintainTimeobj: [],
  intelligenceList: [],
  maintainTypeobj: [],
  maintainList: [],
});
const { maintainList, maintainTypeobj, maintainTimeobj, paramsintel, intelligenceList } = toRefs(data);
//智能推荐池
function getList1() {
  paramsintel.value.workArea = props.workAreaTree.workArea;
  paramsintel.value.workAreaId = props.workAreaTree.workAreaId;
  paramsintel.value.userId = sessionStorage.getItem("userId");
  paramsintel.value.token = sessionStorage.getItem("accessToken");
  selectWeeklyMaintainContentListapi(paramsintel.value).then((res) => {
    if (res.code == 200) {
      intelligenceList.value = res.data;
      maintainList.value = res.data;
      const wxsj = {};
      maintainTimeobj.value = intelligenceList.value.reduce((next, item) => {
        wxsj[item.maintainTime] == undefined ? (wxsj[item.maintainTime] = true & next.push(item)) : "";
        return next;
      }, []);
      const wxlx = {};
      maintainTypeobj.value = intelligenceList.value.reduce((next, item) => {
        wxlx[item.maintainType] == undefined ? (wxlx[item.maintainType] = true & next.push(item)) : "";
        return next;
      }, []);
      maintainchildrenFun();
    }
  });
}
function addButtom(item) {
  emit("intelligenceFun2", item);
  maintainchildrenFun();
}
function maintainchildrenFun() {
  // console.log(props.formaMaintainContentList());
  // if (props.formaMaintainContentList() == undefined) return;
  // maintainList.value = JSON.parse(JSON.stringify(intelligenceList.value));
  // for (let i = 0; i < props.formaMaintainContentList().length; i++) {
  //   const element = props.formaMaintainContentList()[i];
  //   if (element.sources == "周计划") {
  //     for (let a = 0; a < maintainList.value.length; a++) {
  //       if (element.taskId == maintainList.value[a].id) {
  //         maintainList.value.splice(a, 1);
  //         a--;
  //       }
  //     }
  //   }
  // }
}
//查询组织结构
function paramsintelQuery() {
  getList1();
}
//单位
function focusWorkArea() {
  isShowWorkArea.value = true;
}
//树结构的选择单选
function handleCheckTree(data) {
  paramsintel.value.workArea = data.organizationFullName;
  paramsintel.value.workAreaId = data.organizationId;
}
function paramsintelReset() {
  paramsintel.value = {
    workArea: "",
    workAreaId: "",
    maintainTime: "",
    maintainContentId: "",
    btcName: "",
    maintainType: "",
  };
  getList1();
}
</script>
<style scoped lang="scss">
.buttonclass {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
</style>
